web/src/pages/[...listing].astro

482 lines · 13604 bytes

  1---
  2import Layout from '@layouts/Layout.astro';
  3import ListingHero from '@components/things/ListingHero.astro';
  4import ServiceList from '@components/things/ServiceList.astro';
  5import Comments from '@components/things/Comments.svelte';
  6import GitHubDetailedInfo from '@components/things/GitHubDetailedInfo.astro';
  7import PrivacyPolicyDetails from '@components/things/PrivacyPolicyDetails.astro';
  8import WebsiteDetailedInfo from '@components/things/WebsiteDetailedInfo.astro';
  9import DockerDetailedInfo from '@components/things/DockerDetailedInfo.astro';
 10import IosAppDetailedInfo from '@components/things/IosAppDetailedInfo.astro';
 11import AndroidAppDetailedInfo from '@components/things/AndroidDetailedInfo.astro';
 12import DiscordDetailedInfo from '@components/things/DiscordDetailedInfo.astro';
 13import RedditDetailedInfo from '@components/things/RedditDetailedInfo.astro';
 14import SocialShare from '@components/form/Social.astro';
 15import DataActions from '@components/things/DataActions.svelte';
 16import type { AwesomePrivacy, Section, Service } from '../types/Service';
 17import { fetchData, slugify } from '@utils/fetch-data';
 18import { fetchChangelog } from '@utils/fetch-changelog';
 19import { fetchGitHubStats } from '@utils/fetch-repo-info';
 20import { fetchTosdrPrivacy } from '@utils/fetch-privacy-policy';
 21import { fetchWebsiteInfo } from '@utils/fetch-website-info';
 22import { fetchDockerData } from '@utils/fetch-docker-instructions';
 23import { fetchIosInfo } from '@utils/fetch-ios-info';
 24import { fetchAndroidInfo } from '@utils/fetch-android-info';
 25import { fetchPlexusInfo } from '@utils/fetch-plexus-info';
 26import { fetchDiscordInfo } from '@utils/fetch-discord-info';
 27import { fetchRedditInfo } from '@utils/fetch-reddit-info';
 28import { site } from '@utils/config';
 29import Button from '@components/form/Button.astro';
 30
 31interface Props extends Service {
 32	slug: string;
 33	parentSection: Section;
 34	categoryName: string;
 35}
 36
 37const {
 38	name,
 39	description,
 40	url,
 41	github,
 42	tosdrId,
 43	discordInvite,
 44	subreddit,
 45	iosApp,
 46	androidApp,
 47	parentSection,
 48	categoryName,
 49} = Astro.props;
 50
 51const makeKeyWordTag = () => {
 52	const keywords = [
 53		`open source ${parentSection.name}`,
 54		`${parentSection.name} comparison`,
 55		...(parentSection.alternativeTo || []).map(
 56			(alt: string) => `${alt} alternative`,
 57		),
 58		...(parentSection.services || []).map((serv: Service) => `${serv.name} vs`),
 59		'private',
 60		'ad free',
 61		'encrypted',
 62		'open source software',
 63		'privacy respecting apps',
 64		'free tools',
 65	];
 66	return keywords.join(', ');
 67};
 68
 69const makePageTitle = () => {
 70	return `${name} | ${parentSection.name} | ${categoryName} | Awesome Privacy`;
 71};
 72
 73const makeBreadcrumbs = () => {
 74	return [
 75		{ name: 'Home', item: '/' },
 76		{ name: categoryName, item: slugify(categoryName) },
 77		{
 78			name: parentSection.name,
 79			item: `${slugify(categoryName)}/${slugify(parentSection.name)}`,
 80		},
 81		{
 82			name: name,
 83			item: `${slugify(categoryName)}/${slugify(parentSection.name)}/${slugify(name)}`,
 84		},
 85	];
 86};
 87
 88const makeDescriptionTag = () => {
 89	let desc = `Analysis of ${name}, and other privacy-respecting ${parentSection.name} `;
 90	if (parentSection.services) {
 91		desc += `Compare ${parentSection.services.map((s: Service) => s.name).join(' vs ')} more apps. `;
 92	}
 93	if (parentSection.alternativeTo && parentSection.alternativeTo.length > 0) {
 94		desc += `The best secure encrypted alternatives to ${parentSection.alternativeTo.join(', ')}. `;
 95	}
 96	desc += 'All this, and many more free and awesome tools and software.';
 97	return desc;
 98};
 99
100const filterServices = () => {
101	return parentSection.services.filter((s: Service) => s.name !== name);
102};
103
104export async function getStaticPaths() {
105	const pages = await fetchData().then((data) => {
106		const results: Array<Props> = [];
107		if (!data || !data.categories) return results;
108		(data as AwesomePrivacy).categories.forEach((category) => {
109			category.sections.forEach((section) => {
110				const services = (section.services || []).map((service) => {
111					return {
112						slug: `${slugify(category.name)}/${slugify(section.name)}/${slugify(service.name)}`,
113						parentSection: section,
114						categoryName: category.name,
115						...service,
116					};
117				});
118				results.push(...services);
119			});
120		});
121		return results;
122	});
123
124	return pages.map((props: Props) => {
125		return { params: { listing: props.slug }, props };
126	});
127}
128
129const makePaginationLinks = () => {
130	const allServices = parentSection.services || [];
131	const index = allServices.findIndex((item) => item.name === name);
132	const previousItem = index > 0 ? allServices[index - 1].name : null;
133	const nextItem =
134		index < allServices.length - 1 ? allServices[index + 1].name : null;
135	return { previous: previousItem, next: nextItem };
136};
137
138const { previous, next } = makePaginationLinks();
139
140const ignoredSites = ['github.com', 'wikipedia.'];
141
142const githubData = github ? await fetchGitHubStats(github) : null;
143const privacyData = tosdrId ? await fetchTosdrPrivacy(tosdrId) : null;
144const iosData = iosApp ? await fetchIosInfo(iosApp) : null;
145const androidData = androidApp ? await fetchAndroidInfo(androidApp) : null;
146const plexusData = androidApp ? await fetchPlexusInfo(androidApp) : null;
147const discordData = discordInvite
148	? await fetchDiscordInfo(discordInvite)
149	: null;
150const redditData = subreddit ? await fetchRedditInfo(subreddit) : null;
151const dockerData = await fetchDockerData(name);
152const websiteData =
153	url && !ignoredSites.some((s) => url.includes(s))
154		? await fetchWebsiteInfo(url)
155		: null;
156
157const serviceHistory = await fetchChangelog().then(({ entries }) => {
158	const isMatch = (c: { name: string; category: string; section: string }) =>
159		c.name === name &&
160		c.category === categoryName &&
161		c.section === parentSection.name;
162	const isHere = (m: {
163		name: string;
164		to: { category: string; section: string };
165	}) =>
166		m.name === name &&
167		m.to.category === categoryName &&
168		m.to.section === parentSection.name;
169	const results: Array<{
170		date: string;
171		type: 'added' | 'removed' | 'modified' | 'moved' | 'renamed';
172		fields?: string[];
173		from?: { category: string; section: string };
174		previousName?: string;
175		pr?: import('@utils/fetch-changelog').ChangelogPr | null;
176	}> = [];
177	for (const e of entries) {
178		const s = e.changes?.services;
179		const added = (s?.added || []).find(isMatch);
180		const removed = (s?.removed || []).find(isMatch);
181		const modified = (s?.modified || []).find(isMatch);
182		const moved = (s?.moved || []).find(isHere);
183		const renamed = (s?.renamed || []).find(isHere);
184		if (added) results.push({ date: e.date, type: 'added', pr: e.pr });
185		else if (removed) results.push({ date: e.date, type: 'removed', pr: e.pr });
186		else if (modified)
187			results.push({
188				date: e.date,
189				type: 'modified',
190				fields: modified.fields,
191				pr: e.pr,
192			});
193		else if (renamed)
194			results.push({
195				date: e.date,
196				type: 'renamed',
197				previousName: renamed.previousName,
198				from: renamed.from,
199				pr: e.pr,
200			});
201		else if (moved)
202			results.push({ date: e.date, type: 'moved', from: moved.from, pr: e.pr });
203	}
204	return results;
205});
206
207const findPrivacyPolicyLink = () => {
208	if (!privacyData) return null;
209	const docs = privacyData?.parameters?.documents;
210	if (docs) {
211		const pp = (docs || []).find((doc) =>
212			doc.name.toLowerCase().includes('privacy policy'),
213		);
214		if (pp) return pp.url;
215	}
216	return `https://tosdr.org/en/service/${tosdrId}`;
217};
218
219const privacyPolicyLink = findPrivacyPolicyLink();
220
221const catSlug = slugify(categoryName);
222const secSlug = slugify(parentSection.name);
223
224const getApiEndpoint = () => {
225	return `https://api.awesome-privacy.xyz/${catSlug}/${secSlug}/${slugify(name)}`;
226};
227
228const makeSoftwareSchema = () => {
229	const operatingSystem = [
230		iosApp && 'iOS',
231		androidApp && 'Android',
232		url && 'Web',
233	].filter(Boolean);
234	const plainDescription = (description || '')
235		.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
236		.replace(/[*_`~]/g, '')
237		.trim();
238	return {
239		'@context': 'https://schema.org',
240		'@type': 'SoftwareApplication',
241		name,
242		description: plainDescription || makeDescriptionTag(),
243		url,
244		applicationCategory: parentSection.name,
245		...(operatingSystem.length && {
246			operatingSystem: operatingSystem.join(', '),
247		}),
248		...(github && { codeRepository: `https://github.com/${github}` }),
249	};
250};
251---
252
253<Layout
254	title={makePageTitle()}
255	keywords={makeKeyWordTag()}
256	description={makeDescriptionTag()}
257	breadcrumbs={makeBreadcrumbs()}
258	customSchemaJson={makeSoftwareSchema()}
259>
260	<main>
261		<ListingHero
262			service={Astro.props}
263			parentSection={parentSection}
264			categoryName={categoryName}
265			privacyPolicyLink={privacyPolicyLink}
266		/>
267		{
268			privacyData && privacyData.parameters?.points?.length > 0 && (
269				<section>
270					<h2>{name} Privacy Policy</h2>
271					<PrivacyPolicyDetails privacyData={privacyData} />
272				</section>
273			)
274		}
275		{
276			github && githubData && (
277				<section class="github-wrap">
278					<h2>{name} Source Code</h2>
279					<GitHubDetailedInfo gitHubData={githubData} repo={github} />
280				</section>
281			)
282		}
283		{
284			websiteData && (
285				<section>
286					<h2>{name} Website</h2>
287					<WebsiteDetailedInfo url={url} websiteInfo={websiteData} />
288				</section>
289			)
290		}
291		{
292			((androidData && !androidData.error) || plexusData) && (
293				<section>
294					<h2>{name} Android App</h2>
295					<AndroidAppDetailedInfo
296						androidData={androidData}
297						plexusData={plexusData}
298					/>
299				</section>
300			)
301		}
302		{
303			iosData &&
304				typeof iosData === 'object' &&
305				Object.keys(iosData).length > 0 && (
306					<section>
307						<h2>{name} iOS App</h2>
308						<IosAppDetailedInfo url={url} iosData={iosData} />
309					</section>
310				)
311		}
312		{
313			dockerData && dockerData.found && (
314				<section>
315					<h2>{name} Docker</h2>
316					<DockerDetailedInfo docker={dockerData} />
317				</section>
318			)
319		}
320		{
321			(discordData || redditData) && (
322				<section>
323					<h2>{name} Socials</h2>
324					<div class="social-wrap">
325						{discordData && <DiscordDetailedInfo discordData={discordData} />}
326						{redditData && <RedditDetailedInfo redditData={redditData} />}
327					</div>
328				</section>
329			)
330		}
331
332		<section>
333			<h2>{name} Reviews</h2>
334			<Comments client:visible />
335		</section>
336
337		<section>
338			<h2>More {parentSection.name}</h2>
339			<ServiceList
340				services={filterServices()}
341				subHeading={true}
342				noGitHubMetrics={true}
343				buttonLink={`/${catSlug}/${secSlug}`}
344				categoryName={categoryName}
345				sectionName={parentSection.name}
346			/>
347		</section>
348		<section>
349			<h2>About the Data: {name}</h2>
350			<DataActions
351				client:load
352				categoryName={categoryName}
353				sectionName={parentSection.name}
354				serviceName={name}
355				history={serviceHistory}
356			/>
357			<h3>API</h3>
358			<p>
359				You can access {name}'s data programmatically via our API. Simply make a <code
360					>GET</code
361				> request to:
362			</p>
363			<pre><a href={getApiEndpoint()}><code>{getApiEndpoint()}</code></a></pre>
364			<p>
365				The REST API is free, no-auth and CORS-enabled. To learn more, view the <a
366					href="/api">Swagger Docs</a
367				> or read the <a href="/about#api">API Usage Guide</a>.
368			</p>
369		</section>
370
371		<section>
372			<h2>Share {name}</h2>
373			<p>
374				Help your friends compare {parentSection.name}, and pick
375				privacy-respecting software and services.<br />
376				Share {name} and Awesome Privacy with your network!
377				<div>
378					<SocialShare
379						url={`${site}/${catSlug}/${secSlug}/${slugify(name)} `}
380						title={`Checkout ${name}! \n`}
381						description={`Compare #${name} and other privacy-respecting ${parentSection.name} at ` +
382							`Awesome-Privacy.xyz, the free and open source list of private software alternatives. ` +
383							`#privacy #opensource #awesomeprivacy by @Lissy_Sykes`}
384					/>
385				</div>
386			</p>
387		</section>
388
389		<div class="pagination-navigation">
390			{
391				previous ? (
392					<Button url={`/${catSlug}/${secSlug}/${slugify(previous)}`}>
393						<span>← Previous</span>
394						<p>{previous}</p>
395					</Button>
396				) : (
397					<p class="nothing" />
398				)
399			}
400			<a href={`/${catSlug}/${secSlug}`} class="go-to-category">
401				View {parentSection.name} ({(parentSection.services || []).length})
402			</a>
403			{
404				next && (
405					<Button url={`/${catSlug}/${secSlug}/${slugify(next)}`}>
406						<span>Next →</span>
407						<p>{next}</p>
408					</Button>
409				)
410			}
411		</div>
412	</main>
413</Layout>
414
415<style lang="scss">
416	main {
417		margin: var(--space-lg) auto;
418		padding: var(--space-md);
419		width: var(--width-container);
420		max-width: var(--width-container-max);
421		position: relative;
422		@media (max-width: 768px) {
423			max-width: 95%;
424			padding: var(--space-sm);
425			margin: 0 auto;
426		}
427	}
428
429	section {
430		margin: var(--space-md) 0 var(--space-2xl) 0;
431		padding: var(--space-md);
432		min-height: 8rem;
433		position: relative;
434		border: var(--border-heavy);
435		box-shadow: var(--shadow-lg);
436		background: var(--accent-fg);
437	}
438
439	p {
440		margin: var(--space-xs) 0 var(--space-sm) 0;
441	}
442
443	h2 {
444		font-size: var(--text-3xl);
445		margin: -2rem 0 var(--space-md) -2rem;
446		box-shadow: var(--shadow-lg);
447		background: var(--accent);
448		color: var(--accent-fg);
449		width: fit-content;
450		padding: var(--space-xs) var(--space-sm);
451		@media (max-width: 768px) {
452			margin: -2rem auto var(--space-lg) auto;
453		}
454	}
455
456	h3 {
457		font-size: var(--text-lg);
458		margin-bottom: 0;
459	}
460
461	pre a {
462		text-decoration: none;
463		color: var(--foreground);
464		code {
465			background: var(--code-bg);
466			padding: 0.2rem 0.4rem;
467			border-radius: var(--curve-sm);
468			font-family: var(--font-code);
469			font-size: var(--text-sm);
470			@media (max-width: 768px) {
471				white-space: break-spaces;
472			}
473		}
474	}
475
476	.social-wrap {
477		display: flex;
478		gap: var(--space-md);
479		flex-wrap: wrap;
480		justify-content: space-between;
481	}
482</style>